﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../Js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            /******取得页码******/
            $.post("PagedService.ashx", { "acction": "getpagecount" }, function (data, status) {
                for (var i = 1; i <= data; i++) {
                    var pagenum = $("<a href='' id='p" + i + "'>" + i + "</a>");
                    $("#PageBar").append(pagenum);
                }
                $("#PageBar a").click(function (e) {
                    e.preventDefault(); //让事件对象只响应事件，不导向链接地址
                    $.post("PagedService.ashx", { "acction": "getpagedata", "pagenum": $(this).text() }, function (data, status) { //发出Post请求
                        var comments = $.parseJSON(data);       //用JSON反序列化服务器返回的数据
                        //$("#ulComment li").empty();
                        $("#ulComment").empty();                //调用.empty()方法清空ul里的数据
                        for (var i = 0; i < comments.length; i++) {     //for循环取出comments里的每一行数据
                            var comment = comments[i];
                            var li = $("<li><p>" + comment.Msg + "</p><p><span>IP地址：" + comment.IPAddr + "</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>评论时间：" + comment.PostDate + " </span></p></li>");
                            $("#ulComment").append(li);     //添加到页面中
                        }
                    });

                });

            });
        });
    </script>
</head>
<body>
    <ul id="ulComment">
    </ul>
    <div id="PageBar">
    </div>
</body>
</html>
